package ar.edu.caece.compiler.grammars.sample2.factories;

import java.util.Arrays;
import java.util.List;

import ar.edu.caece.compiler.grammars.sample2.tokens.EoFToken;
import ar.edu.caece.compiler.grammars.sample2.tokens.IdToken;
import ar.edu.caece.compiler.grammars.sample2.tokens.NumToken;
import ar.edu.caece.compiler.grammars.sample2.tokens.PlusToken;
import ar.edu.caece.compiler.grammars.sample2.tokens.SampleToken;
import ar.edu.caece.compiler.grammars.sample2.tokens.SuperIdToken;
import ar.edu.caece.compiler.model.LexicalAnalyzer;

public abstract class AbstractTokenVisitorFactory implements TokenVisitorFactory{
	private LexicalAnalyzer analizadorLexico;
	private static SampleToken currentToken;
	
	private static List<SampleToken> tokenList = Arrays.asList(new NumToken("num"),new PlusToken("+"),new NumToken("num2"), 
			new PlusToken("+"),
			new IdToken("id"),new PlusToken("+"),new IdToken("id"), new PlusToken("+"), new SuperIdToken("superId"));
	
	private static int pos = 0;
	
	public void setAnalizadorLexico(LexicalAnalyzer analizadorLexico) {
		this.analizadorLexico = analizadorLexico;
	}

	public LexicalAnalyzer getAnalizadorLexico() {
		return analizadorLexico;
	}
	
	public AbstractTokenVisitorFactory(LexicalAnalyzer analizadorLexico) {
		this.analizadorLexico = analizadorLexico;
	}
	
	public AbstractTokenVisitorFactory() {
		
	}
	
	public static SampleToken nextToken() throws Exception {
		if(pos<tokenList.size()) {
		SampleToken returnToken = tokenList.get(pos);
		pos++;
		currentToken = returnToken;
		return returnToken;
		} else return new EoFToken();
	}
	
	public static void backToken() throws Exception {
 		pos--;
	}
	
	protected SampleToken currentToken() throws Exception {
		return currentToken;
	}
}
